<template>
	<view style="overflow-x: hidden;">
		<view class="verify u-f-ajc u-f-c">
			<image src="https://statics.xmcsrv.net/weixin/userManage/verifyPwd.png" class="img" mode=""></image>
			<view class="verifyDesc">请输入管理员密码</view>
		</view>
		<view class="code">
			<!-- <xt-verify-code size="6" ref="verifyCode" :isFocus="false" inputType="number" cursorColor="#000"
				class="verify-code" v-model="password">
			</xt-verify-code> -->
			<input class="input-code" :focus="true" type="number" maxlength="12" v-model="password"/>
		</view>
		<button class="btn radius-btn" :type="password.length >= 6?'operation':''"  @tap="confirmPass()">确定</button>
	</view>
</template>

<script>
const { turnTenToSixteen } = require('@/utils/util.js');
const { handledoorLockTransparent } = require('@/jvss/pagesDevice/utils/index.js');
	export default {
		data() {
			return {
				password: '',
				type: 1, //1是用户管理 2是门锁设置 3安装设置
				userInfo: {},
				device: {},
				DoorFunction:null,//锁具设置页面能力集
				installSetList:null,//安装设置
				firstFocus:false,
				unload:false,
				isRedirectTo:false
			}
		},
		onLoad(opt) {
			console.log('verifyOpt===>',opt)
			this.type = opt.type
			let enData = decodeURIComponent(opt.device)
			this.device = JSON.parse(enData);
			if(opt.installSetList){
				this.installSetList = JSON.parse(opt.installSetList)
			}
			if(opt.DoorFunction){
				this.DoorFunction = JSON.parse(opt.DoorFunction)
			}
			if(opt.userInfo){
				this.userInfo = JSON.parse(opt.userInfo)
			}
			this.$nextTick(()=>{
				this.firstFocus = true;
			})
			console.log('验证密码===',opt);
		},
		onUnload() {
			this.unload = true;
			if(!this.isRedirectTo){
				this.sendEnd();
			}
		},
		methods: {
			//确认输入管理员密码
			confirmPass() {
				if (this.password.length < 6) {
					return
				}
				this.verifyManagerPwd()
			},
			verifyManagerPwd() {
				uni.showLoading({
					title: '验证中'
				})
				let data = {
					Name: 'OPDoorLockProCmd',
					OPDoorLockProCmd: {
						Cmd: "DoorUser",
						DoorUser: {
							Action: 'Verify',
							Pswd: this.password
						}
					}
				};
				let token = this.device.token;
				getApp().globalData.api.doorLockTransparent(data, token, (result) => {
					uni.hideLoading()
					console.log('验证管理密码',result);
					handledoorLockTransparent(result,(res,Err)=>{
						console.log(res,Err,'handledoorLockTransparent')
						if(Err == '0x00'){
							let settingUrl =
								'/jvss/pagesDevice/device/device-live/door-lock/setting/lockSetting/doorlockSetting?device=' +encodeURIComponent(JSON.stringify(this.device)) + '&DoorFunction=' + JSON.stringify(this.DoorFunction)
							let userUrl =
								`/jvss/pagesDevice/device/device-live/door-lock/userManage/userList?userInfo=${JSON.stringify(this.userInfo)}&device=${encodeURIComponent(JSON.stringify(this.device))}&password=${this.password}`
							let installSetting = 
							    '/jvss/pagesDevice/device/device-live/door-lock/setting/lockSetting/function?token=' + this.device.token + '&title=' +'安装设置'  +'&installSetList='+ JSON.stringify(this.installSetList)
							if(this.type == 3){
								uni.setStorageSync('isInstallverify',true)
							}
							this.isRedirectTo = true
							uni.redirectTo({
								url: this.type == 1 ? userUrl :
								this.type == 2 ? settingUrl:
								installSetting
							})
						}else{
							if(!this.unload){
								uni.showModal({
								    title: '提示',
								    confirmText: '确认',
								    confirmColor: '#1AC0BA',
								    showCancel: false,
								    content: getApp().globalData.errCodeMsg.wakeUpLockBoardCodeMsg[Err] || result.data.msg,
								    success: (res) => {
								        uni.navigateBack({});
										this.sendEnd()
								    },
								});
							}
						}
					},true)
				},false);
			},
			// 发送End结束流程
			sendEnd(){
				let data = {
					Name: 'OPDoorLockProCmd',
					OPDoorLockProCmd: {
						Cmd: "SyncDoorStatus",
						DoorStatus: {
							Status:'End'
						}
					}
				};
				let token = this.device.token;
				getApp().globalData.api.doorLockTransparent(data, token, (result) => {
					console.log('发送End',result);
				},false);
			}
		}
	}
</script>

<style lang="scss">
	.input-code{
		text-align: center;
		font-size: 20px;
		color: #FF0025;
		font-weight: bold;   
		// border-bottom: 1px solid #B9B9B9;
		// padding-bottom: 10px;
		border: 1px solid #B9B9B9;
		padding: 10px;
		border-radius: 10px;
		background-color: #fff;
	}
	.verify-code {
		.xt__verify-code {
			margin: auto;
		}

		.xt__input-ground {
			margin: auto;

			.xt__code-text {
				font-size: 40rpx !important;
			}
		}

		/deep/.xt__code-text {
			font-size: 40rpx !important;
		}

		/deep/.xt__box {
			width: 70rpx !important;
			height: 70rpx !important;
			background: #fff;
			border-radius: 10rpx;
			border: #eee;
			border-width: 1px !important;
			border-style: solid !important;
		}
	}

	.verify {
		margin-top: 150rpx;

		.img {
			width: 376rpx;
			height: 267.5rpx;
		}

		.verifyDesc {
			font-size: 26rpx;
		}
	}

	.code {
		width: 86%;
		margin: auto;
		margin-top: 80rpx;
	}
	.find-food-submit {
		border: 1px solid #B9B9B9;
		background-color: #fff !important;
		color: #FF0025 !important;
	}
	.btn:after {
	    border: none;
    }
	button{
		border-radius: 40rpx;
		width: 86% !important;
		height: 80rpx;
		margin-top: 30rpx;
	}
	.btn{
		background: #B9B9B9;
		color: white;
	}
</style>
